# -*- coding: utf-8 -*-
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.graphics.tsaplots import plot_acf
from matplotlib.pyplot import acorr
from scipy.stats import t

def drawing(data):
    '''
    画出数据随着时间的变化图
    '''
    cols = data.columns
    time_series = range(1,data.shape[0]+1)
    for col in cols:
        fig = plt.figure()
        plt.plot(time_series, data[col])
        plt.xlabel('Time Index', fontsize=16)
        plt.ylabel('Value',  fontsize=16)
        plt.title(f'Sensor_{col}',  fontsize=20)
        fig.savefig(f'../图片/line plot/传感器{col}.png')
        plt.grid()
        plt.show()


def save_medium(verbose=True):
    '''
    数据的统计描述，并保存
    '''
    print('数据的统计信息如下： \n', data.describe())
    data_summary = data.describe()
    save_path = r'../附件/中间数据/数据统计描述.xlsx'
    data_summary.to_excel(save_path)
    
if __name__ == '__main__':
    path = r'../附件/附件1(Appendix 1)2021-51MCM-Problem C.xlsx'
    data = pd.read_excel(path, index_col=1, header=0, parse_dates=True)
    # 删除第一列（时间编号）
    data.drop(data.columns[0], axis=1, inplace=True)
    
    a = data.iloc[:, 5].autocorr(lag=1)
    print(a)
    # save_medium(verbose=True)
    # 画出传感器读数-时间图
    # drawing(data)
    
